package game

import (
	"encoding/json"
	"fmt"
	"gosum/server/src/csv"
	"io/ioutil"
	"os"
)

type PoolInfo struct {
	PoolId        int
	FiveStarTimes int
	FourStarTimes int
	IsMustUp      int //保底
}
type ModPool struct {
	UpPoolInfo *PoolInfo

	player *Player
	path   string
}

func (self *ModPool) AddTimes() {
	self.UpPoolInfo.FiveStarTimes++
	self.UpPoolInfo.FourStarTimes++
}

func (self *ModPool) DoPool() {
	result := make(map[int]int)

	fourNum := 0
	fiveNum := 0

	//非酋测试
	resultEach := make(map[int]int)

	//十连测试
	resultEachTest := make(map[int]int)
	FiveTest := 0

	for i := 0; i < 10000000; i++ {
		self.AddTimes()
		if i%10 == 0 {
			FiveTest = 0
		}
		//1000对应UP池子
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}

		//保底机制
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			newDropGroup := new(csv.DropGroup)
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll
			AddFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if AddFiveWeight < 0 {
				AddFiveWeight = 0
			}
			AddFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if AddFourWeight < 0 {
				AddFourWeight = 0
			}

			for _, config := range dropGroup.DropConfigs {
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.Weight = config.Weight

				if newConfig.Result == 10001 {
					newConfig.Weight = config.Weight + AddFiveWeight
				} else if newConfig.Result == 10002 {
					newConfig.Weight = config.Weight + AddFourWeight
				} else if newConfig.Result == 10003 {
					newConfig.Weight = config.Weight - AddFiveWeight - AddFourWeight
				}

				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			dropGroup = newDropGroup
		}
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				if roleConfig.Star == 5 {
					//十连测试
					FiveTest++
					//五星统计
					resultEach[self.UpPoolInfo.FiveStarTimes]++

					fiveNum++

					self.UpPoolInfo.FiveStarTimes = 0

					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						dropGroup := csv.ConfigDropGroupMap[10012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					fourNum++
					self.UpPoolInfo.FourStarTimes = 0
				}
			}
			result[roleIdConfig.Result]++
		}
		if i%10 == 9 {
			resultEachTest[FiveTest]++
		}
	}

	for k, v := range result {
		fmt.Println("抽中", csv.GetItemName(k), "次数: ", v)
	}
	fmt.Println("抽到4星的次数", fourNum)
	fmt.Println("抽到5星的次数", fiveNum)

	//非酋测试
	for k, v := range resultEach {
		fmt.Println("第", k, "抽中五星次数: ", v)
	}
	//十连
	for k, v := range resultEachTest {
		fmt.Println("十连", k, "黄次数: ", v)
	}
}

func (self *ModPool) HandleUpPoolTen(player *Player) {
	for i := 0; i < 10; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}
		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0

					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
				}
			}
			//fmt.Println(fmt.Sprintf("第%d抽抽中:%s", i+1, csv.GetItemName(roleIdConfig.Result)))
			player.GetModBag().AddItem(roleIdConfig.Result, 1)
		}
	}
	if self.UpPoolInfo.IsMustUp == csv.LOGIC_FALSE {
		fmt.Println(fmt.Sprintf("当前处于小保底区间！"))
	} else {
		fmt.Println(fmt.Sprintf("当前处于大保底区间！"))
	}
	fmt.Println(fmt.Sprintf("当前累计未出5星次数：%d", self.UpPoolInfo.FiveStarTimes))
	fmt.Println(fmt.Sprintf("当前累计未出4星次数：%d", self.UpPoolInfo.FourStarTimes))
}

func (self *ModPool) HandleUpPoolSingle(times int, player *Player) {
	if times <= 0 || times > 100000000 {
		fmt.Println("请输入正确的数值(1~100000000)")
		return
	} else {
		fmt.Println(fmt.Sprintf("累计抽取%d次,结果如下:", times))
	}
	result := make(map[int]int)
	fourNum := 0
	fiveNum := 0
	for i := 0; i < times; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}
		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0
					fiveNum++
					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
					fourNum++
				}
			}
			result[roleIdConfig.Result]++
			player.GetModBag().AddItem(roleIdConfig.Result, 1)
		}
	}
	for k, v := range result {
		fmt.Println(fmt.Sprintf("抽中%s次数：%d", csv.GetItemName(k), v))
	}
	fmt.Println(fmt.Sprintf("抽中4星：%d", fourNum))
	fmt.Println(fmt.Sprintf("抽中5星：%d", fiveNum))
}

func (self *ModPool) HandleUpPoolTimesTest(times int) {
	if times <= 0 || times > 100000000 {
		fmt.Println("请输入正确的数值(1~100000000)")
		return
	} else {
		fmt.Println(fmt.Sprintf("累计抽取%d次,结果如下:", times))
	}
	resultEach := make(map[int]int)
	for i := 0; i < times; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}
		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					resultEach[self.UpPoolInfo.FiveStarTimes]++
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0
					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
				}
			}
		}
	}
	for k, v := range resultEach {
		fmt.Println(fmt.Sprintf("第%d抽抽出5星的次数：%d", k, v))
	}
}

func (self *ModPool) HandleUpPoolFiveTest(times int) {
	if times <= 0 || times > 100000000 {
		fmt.Println("请输入正确的数值(1~100000000)")
		return
	} else {
		fmt.Println(fmt.Sprintf("累计抽取%d次,结果如下:", times))
	}
	resultEachTest := make(map[int]int)
	fiveTest := 0
	for i := 0; i < times; i++ {
		self.AddTimes()

		if i%10 == 0 {
			fiveTest = 0
		}

		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}
		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					fiveTest++
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0
					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
				}
			}
		}
		if i%10 == 9 {
			resultEachTest[fiveTest]++
		}
	}
	for k, v := range resultEachTest {
		fmt.Println(fmt.Sprintf("10连%d黄次数：%d", k, v))
	}
}

func (self *ModPool) HandleUpPoolSingleCheck1(times int, player *Player) {
	if times <= 0 || times > 100000000 {
		fmt.Println("请输入正确的数值(1~100000000)")
		return
	} else {
		fmt.Println(fmt.Sprintf("累计抽取%d次,结果如下:", times))
	}
	result := make(map[int]int)
	fourNum := 0
	fiveNum := 0
	for i := 0; i < times; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}

		//仓检
		fiveInfo, fourInfo := player.GetModRole().GetRoleInfoForPoolCheck()

		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop1(dropGroup, fiveInfo, fourInfo)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0
					fiveNum++
					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
					fourNum++
				}
			}
			result[roleIdConfig.Result]++
			player.GetModBag().AddItem(roleIdConfig.Result, 1)
		}
	}
	for k, v := range result {
		fmt.Println(fmt.Sprintf("抽中%s次数：%d", csv.GetItemName(k), v))
	}
	fmt.Println(fmt.Sprintf("抽中4星：%d", fourNum))
	fmt.Println(fmt.Sprintf("抽中5星：%d", fiveNum))
}

func (self *ModPool) HandleUpPoolSingleCheck2(times int, player *Player) {
	if times <= 0 || times > 100000000 {
		fmt.Println("请输入正确的数值(1~100000000)")
		return
	} else {
		fmt.Println(fmt.Sprintf("累计抽取%d次,结果如下:", times))
	}
	result := make(map[int]int)
	fourNum := 0
	fiveNum := 0
	for i := 0; i < times; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}

		//仓检
		fiveInfo, fourInfo := player.GetModRole().GetRoleInfoForPoolCheck()

		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop2(dropGroup, fiveInfo, fourInfo)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0
					fiveNum++
					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
					fourNum++
				}
			}
			result[roleIdConfig.Result]++
			player.GetModBag().AddItem(roleIdConfig.Result, 1)
		}
	}
	for k, v := range result {
		fmt.Println(fmt.Sprintf("抽中%s次数：%d", csv.GetItemName(k), v))
	}
	fmt.Println(fmt.Sprintf("抽中4星：%d", fourNum))
	fmt.Println(fmt.Sprintf("抽中5星：%d", fiveNum))
}

func (self *ModPool) SaveData() {
	content, err := json.Marshal(self)
	if err != nil {
		return
	}
	err = ioutil.WriteFile(self.path, content, os.ModePerm)
	if err != nil {
		return
	}
}

func (self *ModPool) LoadData(player *Player) {

	self.player = player
	self.path = self.player.localPath + "/pool.json"

	configFile, err := ioutil.ReadFile(self.path)
	if err != nil {
		self.InitData()
		fmt.Println("error")
		return
	}
	err = json.Unmarshal(configFile, &self)
	if err != nil {
		self.InitData()
		return
	}

	if self.UpPoolInfo == nil {
		self.UpPoolInfo = new(PoolInfo)
	}
	return
}

func (self *ModPool) InitData() {
	self.UpPoolInfo = new(PoolInfo)
}

func (self *ModPool) HandleUpPoolTenByMsg(msg []byte) {

	var msgInfo MsgPool
	msgErr := json.Unmarshal(msg, &msgInfo)
	if msgErr != nil {
		fmt.Println("消息解析失败！")
		return
	}
	//msgInfo.PoolType
	for i := 0; i < 10; i++ {
		self.AddTimes()
		//掉落组
		dropGroup := csv.ConfigDropGroupMap[1000]
		if dropGroup == nil {
			return
		}
		//超过FIVE_STAR_TIMES_LIMIT没抽到5星 五星概率提升
		//超过FOUR_STAR_TIMES_LIMIT没抽到4星 四星概率提升
		if self.UpPoolInfo.FiveStarTimes > csv.FIVE_STAR_TIMES_LIMIT || self.UpPoolInfo.FourStarTimes > csv.FOUR_STAR_TIMES_LIMIT {
			//初始化新的掉落组
			newDropGroup := new(csv.DropGroup)
			//掉落组Id和总权重10000不变
			newDropGroup.DropId = dropGroup.DropId
			newDropGroup.WeightAll = dropGroup.WeightAll

			//五星、四星UP的概率提高
			//五星概率提高的比例为 每超过FIVE_STAR_TIMES_LIMIT一次就提升FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			//73 600
			addFiveWeight := (self.UpPoolInfo.FiveStarTimes - csv.FIVE_STAR_TIMES_LIMIT) * csv.FIVE_STAR_TIMES_LIMIT_EACH_VALUE
			if addFiveWeight < 0 {
				addFiveWeight = 0
			}
			//四星概率提高的比例为 每超过FOUR_STAR_TIMES_LIMIT一次就提升FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			//9 5100
			addFourWeight := (self.UpPoolInfo.FourStarTimes - csv.FOUR_STAR_TIMES_LIMIT) * csv.FOUR_STAR_TIMES_LIMIT_EACH_VALUE
			if addFourWeight < 0 {
				addFourWeight = 0
			}

			//读出掉落表中三四五星对应的数据
			for _, config := range dropGroup.DropConfigs {
				//生成新的掉落配置
				newConfig := new(csv.ConfigDrop)
				newConfig.DropId = config.DropId
				newConfig.Result = config.Result
				newConfig.IsEnd = config.IsEnd

				//五星Up的概率 默认+提高的概率 四星Up的概率 默认+提高的概率 三星概率为 默认-五星UP的概率-四星Up的概率
				if config.Result == 10001 {
					newConfig.Weight = config.Weight + addFiveWeight
				} else if config.Result == 10002 {
					newConfig.Weight = config.Weight + addFourWeight
				} else if config.Result == 10003 {
					newConfig.Weight = config.Weight - addFiveWeight - addFourWeight
				}

				//将对应的Up概率添加到新的掉落组中
				newDropGroup.DropConfigs = append(newDropGroup.DropConfigs, newConfig)
			}
			//更新掉落组数据
			dropGroup = newDropGroup
		}
		//取掉落组中的Id
		roleIdConfig := csv.NewGetRandDrop(dropGroup)
		if roleIdConfig != nil {
			//判断抽到的东西是不是角色
			roleConfig := csv.GetRoleConfig(roleIdConfig.Result)
			if roleConfig != nil {
				//抽到五星角色
				if roleConfig.Star == 5 {
					//保底计数清0
					self.UpPoolInfo.FiveStarTimes = 0

					//触发保底
					if self.UpPoolInfo.IsMustUp == csv.LOGIC_TRUE {
						//掉落组设为UP对象
						dropGroup := csv.ConfigDropGroupMap[100012]
						if dropGroup != nil {
							roleIdConfig = csv.NewGetRandDrop(dropGroup)
							if roleIdConfig == nil {
								fmt.Println("数据异常")
								return
							}
						}
					}
					if roleIdConfig.DropId == 100012 {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_FALSE
					} else {
						self.UpPoolInfo.IsMustUp = csv.LOGIC_TRUE
					}
				} else if roleConfig.Star == 4 {
					self.UpPoolInfo.FourStarTimes = 0
				}
			}
			//fmt.Println(fmt.Sprintf("第%d抽抽中:%s", i+1, csv.GetItemName(roleIdConfig.Result)))
			player.GetModBag().AddItem(roleIdConfig.Result, 1)
		}
	}
	if self.UpPoolInfo.IsMustUp == csv.LOGIC_FALSE {
		fmt.Println(fmt.Sprintf("当前处于小保底区间！"))
	} else {
		fmt.Println(fmt.Sprintf("当前处于大保底区间！"))
	}
	fmt.Println(fmt.Sprintf("当前累计未出5星次数：%d", self.UpPoolInfo.FiveStarTimes))
	fmt.Println(fmt.Sprintf("当前累计未出4星次数：%d", self.UpPoolInfo.FourStarTimes))

	//	self.player.ws.Write("")
}
